<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Model\SystemModel;
use App\model\ArticleModel;
use App\Model\CateModel;
use App\Model\LinkModel;
use View;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     * 这里面数据是共享的
     * @return void
     */
    public function boot()
    {
        //获取网站的设置
        $systemModel = new SystemModel;
        $sys = $systemModel->getSys();

        //获取文章的关键字
        $articleModel = new ArticleModel;
        //去重
        $keywords = array_unique($articleModel->getArticleKey());

        //获取友情链接
        $linkModel = new LinkModel;
        $links = $linkModel->getLinksBySort();

        //获取最新文章
        $newArts = $articleModel->getNewArt();
        
        //获取文章分类
        $cateModel = new CateModel;
        $cates = $cateModel->getCates();

        //共享数据
        View()->share([
                        'sys' => $sys , 
                        'keywords' => $keywords,
                        'links' => $links,
                        'newArts' => $newArts,
                        'cates' => $cates,
                    ]);
    }
}
